﻿/**
*	Rect3D
*	@author 	Liam O'Donnell 2008-04-14
**/

package com.spikything.pants3d.objects {
	
	import com.spikything.pants3d.Pants3D;
	import com.spikything.pants3d.core.Physics;
	import com.spikything.pants3d.core.Point3D;
	import com.spikything.pants3d.events.PhysicsEvent;
	import com.spikything.pants3d.objects.PhysicsSprite3D;
	import flash.display.Sprite;
	
	public class Rect3D extends PhysicsSprite3D {
		
		public function Rect3D (x:Number = 0, y:Number = 0, z:Number = 0, child:Sprite = null, width:Number = 100, height:Number = 100, depth:Number = 100, weightless:Boolean = true, frictionless:Boolean = false, ghostMode:Boolean = false) {
			super(x, y, z, child, width, height, depth, weightless, frictionless, ghostMode);
			_id = "Rect3D";
			graphics.beginFill(0x00ff00, .25);
			graphics.drawRect(-w/2, -h/2, w, h);
		}
		
		override protected function onCollision (e:PhysicsEvent):void {
			trace(">> RECT3D COLLISION: " + this.id + " and " + e.data.id);
			var sprite:PhysicsSprite3D = e.data as PhysicsSprite3D;
			if (containsPoint(new Point3D(sprite.px-sprite.vx, sprite.py, sprite.pz))) {
				trace("SIDE HIT");
				sprite.px = sprite.px - px < 0 ? px - w/2 : px+w/2;
				vx += sprite.vx / 2;
				sprite.vx *= Physics.inst.elasticity;
			}
		}
		
	}
	
}